package com.heu.blood.storge.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.heu.blood.common.aop.ControllerLogAnnotation;
import com.heu.blood.storge.vo.BloodTypeWarningVo;
import com.heu.blood.storge.vo.BloodWarningQueryVo;
import com.heu.blood.storge.vo.BloodWarningVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.heu.blood.storge.entity.BloodWarningEntity;
import com.heu.blood.storge.service.BloodWarningService;
import com.heu.blood.common.utils.PageUtils;
import com.heu.blood.common.utils.R;



/**
 * 
 *
 * @author lhh
 * @email lhh1612325771@163.com
 * @date 2024-06-27 22:05:47
 */
@RestController
@RequestMapping("storge/bloodwarning")
public class BloodWarningController {
    @Autowired
    private BloodWarningService bloodWarningService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @ControllerLogAnnotation(module = "血液预警", operate = "分页查询血液预警信息")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = bloodWarningService.queryPage(params);

        return R.ok().put("page", page);
    }

    // 添加根据血液类型进行查询
    @RequestMapping("/queryByBloodType")
    @ControllerLogAnnotation(module = "血液预警", operate = "根据血液类型进行分页查询")
    public R queryByBloodType(BloodWarningQueryVo bloodWarningQueryVo){
        PageUtils page = bloodWarningService.queryByBloodType(bloodWarningQueryVo);

        return R.ok().put("page", page);
    }

    /**
     * 新的根据血液品时间阈值进行血液预警
     */
    @ControllerLogAnnotation(module = "血液预警", operate = "新的根据血液品时间阈值进行血液预警")
    @RequestMapping("/bloodWarningByTime")
    public R bloodWarningByTime(@RequestParam Map<String, Object> params){
        List<BloodWarningVo> bloodWarningVos = bloodWarningService.bloodWarningByTime(params);
        return R.ok().put("data", bloodWarningVos);
    }
    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @ControllerLogAnnotation(module = "血液预警", operate = "根据id查询血液预警信息")
    public R info(@PathVariable("id") Long id){
		BloodWarningEntity bloodWarning = bloodWarningService.getById(id);

        return R.ok().put("bloodWarning", bloodWarning);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @ControllerLogAnnotation(module = "血液预警", operate = "插入血液预警信息")
    public R save(@RequestBody BloodWarningEntity bloodWarning){
		bloodWarningService.saveBloodWarning(bloodWarning);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @ControllerLogAnnotation(module = "血液预警", operate = "更新血液预警信息")
    public R update(@RequestBody BloodWarningEntity bloodWarning){
		bloodWarningService.updateById(bloodWarning);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @ControllerLogAnnotation(module = "血液预警", operate = "根绝id删除血液预警信息")
    public R delete(@RequestBody Long[] ids){
		bloodWarningService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }
    /**
     * 返回低于安全库存的血液类型相关信息
     */
    @GetMapping("/stockWarningList")
    @ControllerLogAnnotation(module = "血液预警", operate = "返回低于安全库存的血液类型相关信息")
    public R getStockWarningList() {
        List<BloodTypeWarningVo> result = bloodWarningService.getStockWarningList();
        return R.ok().put("data", result);
    }

    @GetMapping("/getComponentCategory")
    @ControllerLogAnnotation(module = "血液预警", operate = "根据bloodType返回ComponentCategory")
    public R getComponentCategory(@RequestParam String bloodType) {
        String  result = bloodWarningService.getComponentCategory(bloodType);
        return R.ok().put("data", result);
    }

}
